﻿// This code is released under the BSD license.
namespace PugLib.Benchmarks
{
    using System.Collections.Generic;
    using System.Globalization;
    using System.Linq;
    using System.Text;

    public class TestResultCollection : List<TestResult>
    {
        public string Database { get; set; }

        public new void Add(TestResult data)
        {
            base.Add(data);
        }

        public override string ToString()
        {
            if (this.Count == 0)
            {
                return string.Empty;
            }

            this.Sort();
            int maxLength = this.Max(t => t.TestName.Length);
            StringBuilder sb = new StringBuilder();

            sb.AppendLine(string.Format(CultureInfo.InvariantCulture, "{0}\t{1}", "Test".PadRight(maxLength), "Duration in seconds".PadRight(maxLength)));
            sb.AppendLine(string.Format(CultureInfo.InvariantCulture, "{0}\t{1}", "=".PadRight(maxLength, '='), "=".PadRight(maxLength, '=')));
            this.ForEach(
                trd =>
                {
                    sb.AppendLine(string.Format(CultureInfo.InvariantCulture, "{0}\t{1}", trd.TestName.PadRight(maxLength),
                                                trd.FormattedDuration.PadRight(maxLength)));
                });
            return sb.ToString();
        }
    }
}